//
//  LGOriginalView.m
//  微博
//
//  Created by MS on 15-12-14.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGOriginalView.h"
#import "UIImageView+WebCache.h"
#import "LGPhotosView.h"
@interface LGOriginalView ()
//头像
@property (nonatomic,weak) UIImageView * iconView ;


//昵称
@property (nonatomic,weak) UILabel * nameView ;


//Vip
@property (nonatomic,weak) UIImageView * vipView;


//时间
@property (nonatomic,weak) UILabel * timeView ;


//来源
@property (nonatomic,weak) UILabel * sourceView ;


//正文
@property (nonatomic,weak) UILabel * contentView ;

//配图
@property (nonatomic,weak)LGPhotosView * photosView ;

@end

@implementation LGOriginalView
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self setUpAllsubView];
        self.userInteractionEnabled = YES;
        self.image = [UIImage imageResizingWithName:@"timeline_card_top_background"];
    }
    return self;
}



-(void)setUpAllsubView
{
    //头像
    UIImageView * iconView = [[UIImageView alloc] init];
    [self addSubview:iconView];
    _iconView = iconView;
    
    //昵称
    UILabel * nameView = [[UILabel alloc] init];
    [self addSubview:nameView];
     nameView.font = LGNameFont;
    _nameView = nameView;
    
    //Vip
    UIImageView * vipView = [[UIImageView alloc] init];
    [self addSubview:vipView];
    _vipView = vipView;
    
    //时间
    UILabel * timeView = [[UILabel alloc] init];
    [self addSubview:timeView];
    timeView.font = LGTimeFont;
    _timeView = timeView;
    _timeView.textColor = [UIColor orangeColor];

    //来源
    UILabel * sourceView = [[UILabel alloc] init];
    [self addSubview:sourceView];
    sourceView.font = LGSourceFont;
    _sourceView = sourceView;
    
  
    //正文
    UILabel * contentView = [[UILabel alloc] init];
    [self addSubview:contentView];
    contentView.font = LGTextFont;
    contentView.numberOfLines = 0;
    _contentView = contentView;
    
    //配图
    LGPhotosView * phontosView = [[LGPhotosView alloc] init];
    [self addSubview:phontosView];
    _photosView = phontosView;
}

-(void) setStatusF:(LGStutaesFrame *)statusF
{
    _statusF = statusF;
    
    // 设置frame
    [self setUpFrame];
    // 设置data
    [self setUpData];
    
}

-(void)setUpData
{
    LGStatus * status = _statusF.statues;
    
 
    // 头像
    [_iconView sd_setImageWithURL:status.user.profile_image_url placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    
    // 昵称
    if (status.user.vip) {
        _nameView.textColor = [UIColor orangeColor];
    }else{
        _nameView.textColor = [UIColor blackColor];
    }
    _nameView.text = status.user.name;
    
    // vip
    NSString *imageName = [NSString stringWithFormat:@"common_icon_membership_level%d",status.user.mbrank];
    UIImage *image = [UIImage imageNamed:imageName];
    
    _vipView.image = image;

    // 时间
    _timeView.text = status.created_at;
    
    // 来源
    
    _sourceView.text = status.source;
    
    // 正文
    _contentView.text = status.text;
    
    _photosView.pic_urls = status.pic_urls;
    
}

- (void)setUpFrame
{
    // 头像
    _iconView.frame = _statusF.originaIconFrame;
    _iconView.layer.cornerRadius =_iconView.frame.size.width*0.5;
    _iconView.clipsToBounds = YES;
    // 昵称
    _nameView.frame = _statusF.originaNameFrame;
    
    // vip
    if (_statusF.statues.user.vip) { // 是vip
        _vipView.hidden = NO;
        _vipView.frame = _statusF.originaVipFrame;
       
    }else{
        _vipView.hidden = YES;
    }
    // 时间
    //时间
    CGFloat timeX = _nameView.frame.origin.x;
    CGFloat timeY = CGRectGetMaxY( _nameView.frame) + LGStatusCellMargin * 0.5;
    CGSize timeSize = [_statusF.statues.created_at sizeWithFont:LGTimeFont];
    _timeView.frame = (CGRect){{timeX,timeY},timeSize};
    
    
    //来源
    CGFloat sourceX = CGRectGetMaxX( _timeView.frame) + LGStatusCellMargin;
    CGFloat sourceY = timeY;
    CGSize sourceSize = [_statusF.statues.source sizeWithFont:LGSourceFont];
    
    _sourceView.frame = (CGRect){{sourceX,sourceY},sourceSize};
    
    // 正文
    _contentView.frame = _statusF.originaContentFrame;
    
    _photosView.frame = _statusF.originaPhontosFrame;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
